package com.fjrz.bbxwj.main.access

import android.widget.TextView
import android.widget.Toast
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.fjrz.bbxwj.R
import com.fjrz.bbxwj.library.adapter.ScrollPickerAdapter.ScrollPickerAdapterBuilder
import com.fjrz.bbxwj.main.host.MainActivity
import com.fjrz.bbxwj.mode.vm.CommonViewModel
import com.module.lemlin.base.loadCenterImage
import com.module.lemlin.mode.ViewModeActivity
import com.module.lemlin.rxhttp.Status
import kotlinx.android.synthetic.main.activity_splash.*


class SplashActivity : ViewModeActivity<CommonViewModel>() {

    override fun viewModel(): CommonViewModel {
        return createViewModel()
    }

    override val layoutResId: Int
        get() = R.layout.activity_splash

    override fun initData() {
        viewModel.commonSplash()
        Thread {
            Thread.sleep((1500))
            runOnUiThread { action() }
        }.start()
    }

    override fun initViewMode() {
        viewModel.commonSplashLiveData.observe(this as LifecycleOwner, Observer { response ->
            if (response.status == Status.FAILURE) {
                finish()
            }
            if (response.status != Status.SUCCESS)
                return@Observer
            val data = response.httpData?.data
                ?:return@Observer
            ivSplashImage.loadCenterImage(data)
        })
    }

    private fun action() {
//        val token: String? = SPStaticUtils.getString(TOKEN, (null))
//        if (token == null) {
//            AccessActivity.open(activity = this)
//        } else {
//            MainActivity.open(activity = this)
//        }
        MainActivity.open(activity = this)
    }

    override fun onStop() {
        super.onStop()
        finish()
    }
}